/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmHistDatSocDet.java
 *
 * Created on 03-sep-2011, 22:12:10
 */

package GUI;

import Negocio.ClienteDatSoc;
import TablasAuxiliares.TAEstadosCiviles;
import Util.FormatoFecha;
import Util.Varios;
import java.util.Date;

/**
 *
 * @author Javi
 */
public class frmHistDatSocDet extends javax.swing.JDialog {
    //Indica la operación que se está realizando
    private char _cOperacion;
    //Referencia al formulario padre
    private frmHistDatSoc _frmPadre;
    //Referencia al objeto de datos principal
    private ClienteDatSoc _oClienteDatSoc;


    /** Creates new form frmHistDatSocDet */
    public frmHistDatSocDet(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** Creates new form frmHistDatSocDet */
    public frmHistDatSocDet(frmHistDatSoc parent, boolean modal) {
        super(parent, modal);
        this._frmPadre = parent;
        //Inicializo la referencia al objeto de datos del formulario padre.
        this._oClienteDatSoc = parent.getoObjetoDatos();
        initComponents();
        //Los combos se cargan a partir de las tablas 1 SOLA VEZ, al crear el formulario.
        this.cargarCombos();
    }

    /*
     * Inicializa los combos a partir de las tablas auxiliares en forma "codigo - descripcion"
     */
    private void cargarCombos(){
        //Datos sociales
        Varios.cargaCombo (jCBEstadoCivil, new TAEstadosCiviles());
    }

    public void inicializaFormulario ( char cOperacion ){
        //Inicializo el código de operación
        this._cOperacion = cOperacion;
        //Carga los datos de la clase
        this.claseAPantalla();
        //Inicializa los controles necesarios
        this.inicializaControles();
    }

    /*
     * Este método carga los atributos de la clase los controles del formulario de entrada.
     */
    private void claseAPantalla(){
        //Clase ClienteDatSoc
        this.jTFIdClienteSoc.setText( Integer.toString( this._oClienteDatSoc.getiIdCliente()));
        //Controlo si el campo clave fecha viene a nulo (solo en el insert) y en ese caso pongo la fecha de hoy
        this.jFTFFechaSoc.setValue ( (this._oClienteDatSoc.getdFecha()== null)? new Date() : this._oClienteDatSoc.getdFecha());
        Varios.seleccionaItemCombo (jCBEstadoCivil, this._oClienteDatSoc.getsEstadoCivil() );
        this.jFTFNumHijosPersonas.setValue(this._oClienteDatSoc.getiNumHijosPersonas());
    }

    /*
     * Este método carga y habilita/inhabilita los controles que sean necesarios
     */
    private void inicializaControles (){
        //Actualizo el título de la ventana en función de la operación.
        this.setTitle( this._frmPadre.getTitle() + " - " + Varios.getLiteralOperacion(this._cOperacion) );
        //Desactivar los controles en la baja y en la consulta y activarlos en el alta o la modificación
        if ( this._cOperacion == 'C' || this._cOperacion == 'B')
            Varios.SetEnabledControles( this.jPanel3, false );
        else
            Varios.SetEnabledControles( this.jPanel3, true );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jCBEstadoCivil = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jLabel48 = new javax.swing.JLabel();
        jTFIdClienteSoc = new javax.swing.JTextField();
        jLabel49 = new javax.swing.JLabel();
        try{
            jFTFFechaSoc = new javax.swing.JFormattedTextField( new FormatoFecha() );
            jFTFNumHijosPersonas = new javax.swing.JFormattedTextField();
            jButtonAceptar = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

            jLabel12.setText("Estado civil");

            jCBEstadoCivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

            jLabel13.setText("Numero de hijos/personas a su cargo");

            jLabel48.setText("IdCliente");

            jTFIdClienteSoc.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTFIdClienteSocActionPerformed(evt);
                }
            });

            jLabel49.setText("Fecha actualización");

        }catch (Exception e){
            e.printStackTrace();
        }

        jFTFNumHijosPersonas.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jFTFNumHijosPersonas, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jCBEstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel48)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTFIdClienteSoc, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel49)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jFTFFechaSoc, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(143, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTFIdClienteSoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel49)
                        .addComponent(jFTFFechaSoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel48))
                .addGap(72, 72, 72)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCBEstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addGap(24, 24, 24)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jFTFNumHijosPersonas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(122, Short.MAX_VALUE))
        );

        jButtonAceptar.setText("Aceptar");
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(257, Short.MAX_VALUE)
                .addComponent(jButtonAceptar)
                .addGap(245, 245, 245))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jButtonAceptar)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTFIdClienteSocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTFIdClienteSocActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTFIdClienteSocActionPerformed

    private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
        setVisible(false);
}//GEN-LAST:event_jButtonAceptarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JComboBox jCBEstadoCivil;
    private javax.swing.JFormattedTextField jFTFFechaSoc;
    private javax.swing.JFormattedTextField jFTFNumHijosPersonas;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField jTFIdClienteSoc;
    // End of variables declaration//GEN-END:variables

}
